package com.ryl.yomall.weball.controller;

import com.ryl.yomall.model.activity.SeckillGoods;
import com.ryl.yomall.activity.client.SecKillFeignClient;
import com.ryl.yomall.model.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.List;
import java.util.Map;

/**
 * @Date 19:33
 * @Author ryl
 * 秒杀管理
 */
@Controller
public class SecKillController {
    @Autowired
    private SecKillFeignClient secKillFeignClient;

    /**
     * 秒杀管理
     */
    @GetMapping("/index")
    public String index(Model model){
        List<SeckillGoods> list = secKillFeignClient.list ( );
        model.addAttribute ( "list",list );
        return "seckill/index";
    }
    /**
     * 去商品详情页面
     */
    @GetMapping("/seckill/{skuId}.html")
    public String seckillItem(@PathVariable Long skuId,Model model){
        SeckillGoods seckillGoods = secKillFeignClient.getSeckillGoods(skuId);
        model.addAttribute("item",seckillGoods);
        return "seckill/item";
    }
    /**
     * 立即去抢购页面
     */
    @GetMapping("/seckill/queue.html")
    public String queue(Long skuId,String skuIdStr,Model model){

        model.addAttribute ( "skuId",skuId );
        model.addAttribute ( "skuIdStr",skuIdStr );
        return "seckill/queue";
    }
    /**
     * 确认订单
     * @param model
     * @return
     */
    @GetMapping("seckill/trade.html")
    public String trade(Model model) {
        Result<Map<String, Object>> result = secKillFeignClient.trade();
        if(result.isOk()) {
            model.addAllAttributes(result.getData());
            return "seckill/trade";
        } else {
            model.addAttribute("message",result.getMessage());

            return "seckill/fail";
        }
    }



}
